import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router/router'
import axios from 'axios'
import VueAxios from 'vue-axios'
import simpleVueValidator from 'simple-vue-validator'
import Vuex from 'vuex'

import App from './App.vue'

Vue.use(VueRouter)
Vue.use(VueAxios, axios);
Vue.use(simpleVueValidator);
Vue.use(Vuex);

Vue.config.productionTip = false;

const router = new VueRouter({
    routes
});
router.beforeEach((to, from , next) => {
    if(!sessionStorage.getItem('token')){
        if (to.path !== '/login') {
            return next({path: '/login'});
        }else {
            next();
        }
    }else{
        if (to.path === '/login') {
            return next({path: '/'});
        }
        next();
    }
});

new Vue({
    el: '#app',
    router,
    template: '<App/>',
    components: { App }
});